package cn.macswelle.campusecurity.database.repositories;

import cn.macswelle.campusecurity.database.entities.Location;
import cn.macswelle.campusecurity.database.entities.Personnel;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Repository
public interface LocationRepository extends JpaRepository<Location, String>,
  JpaSpecificationExecutor<Location> {
  @Query("select r.location as id, r.location.name as name, " +
    "r.event as description, r.createTime as time, r.file as file " +
    "from Record r where r.personnel.id=?1")
  List<Map<String, String>> findByPersonnel(String personnelId);

  @Query("select r.personnel.id as id, r.personnel.name as name from Record r " +
    "where r.createTime > ?2 and r.createTime <?3 and r.location.id = ?1")
  List<Map<String,String>> kaoQin(String locationId, Long start, Long end);
}
